package com.jt.provider.controller;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 构建RequestOriginParser对象，对请求数据进行解析
 * */
@Component
public class DefaultRequestOriginParser implements RequestOriginParser {
    /**
     * 当设置了授权规则后，系统底层拦截请求，会调用此方法，对数据进行解析
     * http://ip:port/path?origin=aaa
     * */
    @Override
    public String parseOrigin(HttpServletRequest httpServletRequest) {
//        String origin = httpServletRequest.getParameter("origin");
//        return origin;
        String ip = httpServletRequest.getRemoteAddr();
        System.out.println("ip: " + ip);
        return ip;
    }
}
